package chatServerMain;

import java.io.*;
import java.net.MalformedURLException;
import java.rmi.RemoteException;

import chat.model.*;
import chatServer.controller.*;
/**
*   A simple Chat Server program that accompanies the Chat Client program.  Its main function is to allow easy 
*  communication to and from the Client group (one or more).
*
* @author Tung Nguyen, Trung V Hoang, Rob Bernard, Justin Semmel
* @see java.util.Observable
* @since September 2012 
*/

public class ChatServerMain {
	/*  'chatServerMain.java'  created by: Team N3 for Swinburne Uni HET715s2/Dr. Recep Ulusoy, 2/10/2012 v0.0 (final)
	*   ==============================================================================
	*
	*   A simple Chat Server program that accompanies the Chat Client program.  Its main function is to allow easy 
	*  communication to and from the Client group (one or more).
	*
	*   It monitors packets on its Server PC TCP Port 6666, then echos any packets back to the Client group, along. 
	*   with the (version 4) IP of the sending PC.  
	*   
	*
	*       NOTE:   a simple diagnostic log of Server activity is available on the CLI Window display.
	*   
	*   	Java Code Writers:  		Tung Nguyen and Trung Hoang      
	*	Embedded documentation:              Rob Bernard
	*	JavaDoc development:		Justin Semmel
	*
	*
	*  The full program requires the following to be present in a PC to operate:
	*  
	*        - An Ethernet Port, managed by the Windows O/S (or similar);
	*        - a Java Machine (pref. JRE6 or better) with the usual libraries (to run it - see User Manual), and ....
	*        - a User Manual in older 'WORD' format ('J715projectTASK1/TASK2manual.doc').
	*
	*
	*  OPERATION:
	*
	*	It just dumbly invokes the ChatServerController start method. 
	*
	*  CLASSES CALLED:  ChatServerController.
	*  ==============    Class and Method summary.  (done by Justin in JavaDocs?)
	*/
	
	public static void main(String []args) throws RemoteException, MalformedURLException
	{
		ChatServerController server = new ChatServerController();
		server.ReadServerFile(ApplicationConstant.serverFile);
		
		//while there is an active server, we will be the backup server.
		while (server.checkActiveServer())
		{
			//cause the delay so we don't cause too much traffic in the network.
			try {
				Thread.sleep(ApplicationConstant.DEFAULT_SLEEP_TIME);
			} catch (InterruptedException e) {				
				e.printStackTrace();
			}
		}
		
		//when there is no active server then we become the active server.
		server.start();
	}
}